/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package classesMiolo;

/**
 *
 * @author thiago
 */
public class Formatador {
    
    public static String formataData(String s){
        
        StringBuilder bd = new StringBuilder(s);
        
        if(s.length() > 9){
            return bd.toString().substring(0,9);
        }
        
        if(s.length() == 2 || s.length() == 5){
            bd.append("/");
        }
        
        return bd.toString();
        
    }
    
    public static String formataCPF(String s){
        
        StringBuilder bd = new StringBuilder(s);
        
        if(s.length() > 13){
            return bd.substring(0,13);
        }
        
        if(s.length() == 3 || s.length() == 7){
            bd.append(".");
        }
        
        if(s.length() == 11){
            bd.append("-");
        }
        
        return bd.toString();
        
    }
    
    public static String formataTelefone(String s){
        
        StringBuilder bd = new StringBuilder(s);
        
        if(s.length() > 12){
            return bd.substring(0,12);
        }
        
        if(s.length() == 0){
            bd.append("(");
        }
        
        if(s.length() == 3){
            bd.append(")");
        }
        
        if(s.length() == 8){
            bd.append("-");
        }
        
        return bd.toString();
        
    }
    
    public static String formataHora(String s){
        
        StringBuilder bd = new StringBuilder(s);
        
        if(s.length() > 4){
            return bd.substring(0,4);
        }
        
        if(s.length() == 2){
            bd.append(":");
        }
        
        return bd.toString();
        
    }
    
    public static String formataCEP(String s){
        
        StringBuilder sb = new StringBuilder(s);
        
        if(s.length() > 8){
            return sb.substring(0,8);
        }      
        
        if(s.length() == 5){
            sb.append("-");
        }
        
        return sb.toString();
        
    }

    
}
